package person.wend.springbootlearnexample2.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class CustomHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        // 这里可以添加具体的健康检查逻辑
        boolean isHealthy = checkCustomCondition();
        if (isHealthy) {
            return Health.status("up").withDetail("status", "服务正在运行").build();
        } else {
            return Health.status("down").withDetail("status", "服务出现问题").build();
        }
    }

    private boolean checkCustomCondition() {
        // 这里可以添加具体的健康检查逻辑
        // 例如检查某个服务是否可用、某个文件是否存在等
        return Math.random() > 0.5; // 简单示例，随机返回健康状态
    }
}